package com.weic.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.InternalResourceView;
import org.springframework.web.servlet.view.RedirectView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
public class MyController {

    @RequestMapping(value = "/firstPage")
    public String firstPage() {
        System.out.println("firstPage");
        return "first";
    }

    /**
     * SpringMVC方式请求转发
     * forward关键字可以省略
     *
     * @return
     */
    @RequestMapping(value = "/demo1")
    public String demo1() {
        //return "forward：/forwardPage.jsp";
        System.out.println("forwardPage");
        return "/WEB-INF/view/forwardPage.jsp";
    }

    /**
     * SpringMVC方式请求重定向
     * redirect关键字不可以省略
     *
     * @return
     */
    @RequestMapping(value = "/demo2")
    public String demo2(HttpServletRequest request, HttpServletResponse response) throws Exception {
        System.out.println("redirectPage......");
        String str = "redirect:/WEB-INF/view/redirectPage.jsp";
        System.out.println(str);
        return str;
    }

    /**
     * 为什么不能访问到WEB-inf中的资源？？
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/demo3")
    public View testView(HttpServletRequest request,HttpServletResponse response) {
        View view = null;
        //view = new InternalResourceView("/WEB-INF/view/forwardPage.jsp");
        view = new RedirectView(request.getContextPath() + "/WEB-INF/view/second.jsp");
        return view;
    }
}
